package com.xxx.demo.controller;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@Controller
@RequestMapping("/manage")
public class YanZhengMa {
    @RequestMapping("/yanZhengMa")
    public String yanzhengMa(HttpSession session, HttpServletResponse response) throws IOException {
        //创建一个验证码对象
        LineCaptcha lineCaptcha= CaptchaUtil.createLineCaptcha(200,100);
        //输出验证码中随机的那个文字
        System.out.println(lineCaptcha.getCode());
        //session中存储验证码对象，将来用户输入图片中文字后调用verify方法进行验证
        session.setAttribute("lineCaptcha",lineCaptcha);
        //将带有混淆的 随机文字的图片输出到客户端
        lineCaptcha.write(response.getOutputStream());
        response.getOutputStream().close();
        return null;
    }
}
